package Structural.Proxy.demo3;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author : yue.cao
 * @since : 2021-04-29
 */
public class ProxyDemo3 {

	public static void main(String[] args) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(Tank.class);
		enhancer.setCallback(new MethodInterceptor() {
			@Override
			public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
				System.out.println("Before");
				Object o1 = methodProxy.invokeSuper(o, objects);
				System.out.println("After");
				return null;
			}
		});
		Tank tank = ((Tank) enhancer.create());
		tank.move();
	}
}

